﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Tanks
{
    class MessageBoxExceptionsCatcher : ExceptionsCatcher
    {
        public MessageBoxExceptionsCatcher()
        {
        }

        public override void Execute(ExecuteFunction function)
        {
            try
            {
                function();
            }
            catch (Exception ex)
            {
                string message = ex.TargetSite + "\n" + ex.Message + "\n";
                Exception excpt = ex.InnerException;
                while (excpt != null)
                {
                    message += "\n" + excpt.TargetSite + "\n" + excpt.Message + "\n";
                    excpt = excpt.InnerException;
                }
                message += ex.StackTrace;
                MessageBox.Show(message, ex.GetType().FullName, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }
}
